package func;

 class Father {

        public int age;
        public String name;
     public Father(int age, String name) {
         this.age = age;
         this.name = name;
     }
     public void eat(){
         System.out.println(this.name+"正在吃饭......");
     }
 }
class Dog extends Father {

    public Dog(int age, String name) {
        super(age, name);
    }
    @Override//重写
    public void eat(){
        System.out.println(this.name+ " 正在休息......");
    }
}
public class Test {
     public static void fuc(Father father){    //方法参数声明为父类 Father 类型，但实际调用时可以传入 Father 类的任意子类对象
         father.eat();       //father调用的对象不一样                          //若子类没重写，会调用父类 Animal 的 eat()
     }                                          //若子类重写，才会会优先执行子类重写后的方法，由传入子类对象的决定
                                                //可以看作引用
    public static void main(String[] args) {
        Dog dog=new Dog(18,"旺财");// 传入子类对象，调用子类重写的 eat()
        fuc(dog);
    }

    public static void main1(String[] args) {
        Father father=new Dog(9,"旺财");
    }
}